import Toast from 'tdesign-miniprogram/toast/index';

import {
  putPerson
} from '@/services/usercenter/fetchPerson'

Page({
  data: {
    text: '',
    label: '内容',
    key: '',
  },
  onLoad(options) {
    const userInfo = wx.getStorageSync('userInfo')

    const {
      text,
      label,
      key
    } = options;
    wx.setNavigationBarTitle({
      title: label,
    })
    this.setData({
      text,
      label,
      key,
      userInfo,
    });
  },
  async onSubmit() {
    const {
      text,
      key,
      userInfo
    } = this.data
    await putPerson({
      [key]: text,
      id: userInfo.id
    })
    Toast({
      context: this,
      selector: '#t-toast',
      message: '修改成功',
      theme: 'success',
    });
  },
  onClose() {
    wx.navigateBack({
      backRefresh: true
    });
  },
  clearContent() {
    this.setData({
      text: '',
    });
  },
});